package com.darren.framework.task;

import java.sql.SQLException;

import javax.annotation.Resource;
import javax.naming.NamingException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import com.darren.framework.service.SystemParameterService;
/**
 * <pre>
 * *********************************************
 * Copyright Darren Zhou.
 * All rights reserved.
 * Description: Timing task to refresh system parameter
 * HISTORY:
 * *********************************************
 *  Version		Date			Author	   		Description
 *   v1.0     2018-02-28  		Darren Zhou    refresh system parameter
 * 
 * *********************************************
 * </pre>
 */

@Component
public class SystemParameterJob {

	private Logger logger = LogManager.getLogger(SystemParameterJob.class);
	
	@Resource
	private SystemParameterService systemParameterService;	

	/**
	 * 定时清除系统参数缓存
	 * @throws SQLException
	 * @throws NamingException
	 */
	@Scheduled(cron = "0 * * * * ?")
	public void refreshSystemParameter() throws SQLException, NamingException {			
		try{
			StopWatch stopWatch = new StopWatch();
			stopWatch.start();
			logger.info("System parameters refresh job launch start..." + System.currentTimeMillis());
			systemParameterService.clearSystemParameter();
			logger.info("System parameters refresh job launch end..." + System.currentTimeMillis());
			stopWatch.stop();
			logger.info("System parameters refresh job launch total time..." + stopWatch.getTotalTimeMillis());
		}catch(Exception e){
			logger.error(e.getMessage(),e);
		}
	}
	
}
